package tacticalLayer.tactics;

import org.jdom.Element;
import org.w3c.dom.Node;

import util.XMLWriter;

/*
 * This tactic simply keeps the unit standing, and attacks back if it is under attack
 */

public class IdleTactic extends Tactic {
	public IdleTactic(int unitID) {
		super(unitID);
	}
	
	/*
	 * Returns the tactic to be executed in the next cycle ("null" means end of tactic)
	 */
	public Tactic cycle(Node gameState) {
		// Check if unit under attack
		// ...
		
		// If unit under attack, then fight back or retreat
		// ...
		return this;
	}
	
	public void writeXML(XMLWriter w) {
		w.tag("tactic type=\"idle\"");
		{
			w.tag("unit-id", m_unitID);
		}
		w.tag("/tactic");
	}
	protected static IdleTactic loadTacticFromXML(Element e) {
		assert e.getName().equals("tactic") :
			"IdleTactic.loadFromXML: Invalid XML Element " +	e.getName();
		assert e.getAttributeValue("type").equals("idle") :
			"IdleTactic.loadFromXML: Invalid Tactic type " +	
			e.getAttributeValue("type");
		
		return new IdleTactic(Integer.parseInt(e.getChildText("unit-id")));
	}
}
